"""
定义向backend装入全部数据的线程函数

"""
import threading
from PyMimircache.cacheReader.requestItem import Req
from PyMimircache import Cachecow


class BACKEND(threading.Thread):
    def __init__(self,tid,ssd_cache,trace_path):
        threading.Thread.__init__(self)

        self.tid=tid
        self.ssd_cache=ssd_cache
        self.trace_path=trace_path


    def run(self):
        ssd_backend(self.ssd_cache,self.trace_path,self.tid)
        # test(self.tid,self.list)

def ssd_backend(ssd_cache,trace_path,tid):
    # 在back_end的ssd中装入全部数据
    c=Cachecow()
    reader=c.open(trace_path)
    n_req=reader.get_num_of_req()
    for n in range(n_req):
        request=reader.read_one_req()
        req=Req(request)
        # print("in thread ",tid,"ssd access ",req.item_id)
        ssd_cache.access(req)

    # print("back end ssd_cache info-------------------------------------------")
    # print(ssd_cache)
    # print("back end ssd_cache info-------------------------------------------")

def test(tid,a_list):
    for i in range(10):
        a_list.append(i)
        print("in thread ",tid,", append ",i)
